package com.cheung.leetcode.str;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.str
 * @Author :  cheungming
 * @CreateTime : 2024-05-07 08:34:56
 * @Description : 字符串反转
 * @Version : 1.0
 */
public class Code344Test {


    public void reverseString(char[] s) {

        for (int i = 0, j = s.length - 1; i < s.length / 2; i++, j--) {
            char temp = s[i];
            s[i] = s[j];
            s[j] = temp;
        }
    }

    @Test
    public void test1() {
        char[] s = {'h', 'e', 'l', 'l', 'o'};
        char[] r = {'o', 'l', 'l', 'e', 'h'};
        reverseString(s);
        assert Arrays.equals(s, r);
    }

    @Test
    public void test2() {
        char[] s = {'H', 'a', 'n', 'n', 'a', 'h'};
        char[] r = {'h', 'a', 'n', 'n', 'a', 'H'};
        reverseString(s);
        assert Arrays.equals(s, r);
    }

    @Test
    public void test3() {
        char[] s = {'a'};
        char[] r = {'a'};
        reverseString(s);
        assert Arrays.equals(s, r);
    }
}
